function bindEvents(bindings) {
    for (var i in bindings) {
        if (bindings[i].selector) {
            $$(bindings[i].element).on(bindings[i].event, bindings[i].selector, bindings[i].handler);
        } else {
            $$(bindings[i].element).on(bindings[i].event, bindings[i].handler);
        }
    }
}

var cityScreen = ['北京', '天津', '重庆', '上海', '河北', '河南', '山西', '山东', '辽宁', '吉林', '黑龙江', '江苏', '浙江', '安徽', '福建', '湖北', '湖南', '江西', '广东', '广西', '贵州', '四川', '云南', '海南', '陕西', '甘肃', '宁夏', '青海', '西藏', '新疆', '内蒙古']
var kemuScreen = ['理科', '文科']
var nianfenScreen = ['2017']

var batchQuery = {
    province: xhr.getSearch('province') || '北京',
    subject: xhr.getSearch('subject') || '理科',
    year: xhr.getSearch('year') || '2017',
    initialize: function () {
        $$('.city-test').html(this.province)
        $$('.kemu-test').html(this.subject)
        $$('.nianfen-test').html(this.year)
        this.getInitData()
        this.bindEvent()
    },
    getInitData: function () {
        myApp.showIndicator();

        this.onepointline()
    },
    onepointline() {
        var param = {
            province: this.province,
            subject: this.subject,
            year: this.year
        }
        xhr.onepointline(param, function (res) {
            var output = tplManager.renderTplById('tplOne', res.data)
            $$('#rank-list').html(output)
        })
    },
    bindEvent: function () {
        var bindings = [
            {
                'element': '.page',
                'event': 'click',
                'selector': '.city',
                'handler': this.openPop('cityScreen')
            }, {
                'element': '.page',
                'event': 'click',
                'selector': '.kemu',
                'handler': this.openPop('kemuScreen')
            }, {
                'element': '.page',
                'event': 'click',
                'selector': '.nianfen',
                'handler': this.openPop('nianfenScreen')
            }, {
                'element': '.pages',
                'event': 'click',
                'selector': '#province li',
                'handler': this.selectProvince()
            }, {
                'element': '.pages',
                'event': 'click',
                'selector': '.close-picker',
                'handler': this.switchImg()
            }
        ];
        utils.bindEvent(bindings);
    },
    switchImg: function () {
        return function (event) {
            $$('.switch-img').attr('src', './img/down.png')
        }
    },
    openPop: function (type) {
        return function (event) {
            $$(this).find('img').attr('src', './img/up.png')
            var output;
            switch (type) {
                case 'cityScreen':
                    output = tplManager.renderTplById('tplScreenCity', cityScreen)
                    break;
                case 'kemuScreen':
                    output = tplManager.renderTplById('tplScreenKemu', kemuScreen)
                    break;
                case 'nianfenScreen':
                    output = tplManager.renderTplById('tplScreenNianfen', nianfenScreen)
                    break;
                default:
                    break;
            }


            $$('#province').html(output)

            myApp.pickerModal('.picker-info')
        }
    },
    selectProvince() {
        var self = this
        return function (event) {
            var id = $$(this).data('id'),
                text = $$(this).data('text');

            if (id === 'province') {
                self.province = text
                $$('.city-test').text(text)
            } else if (id === 'subject') {
                self.subject = text
                $$('.kemu-test').text(text)
            } else if (id === 'nianfen') {
                self.year = text
                $$('.nianfen-test').text(text)
            }
            self.onepointline()
            $$('.switch-img').attr('src', './img/down.png')
            myApp.closeModal('.picker-info')
        }
    }
}
batchQuery.initialize()